﻿using System.Configuration.Install;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Collections;
using System.Linq;
using System.Text;
using log4net;
using System;


namespace Updater.Common
{
    [RunInstaller(true)]
    class DBInstall : Installer
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(Installer));
        
        /// <summary>
        /// This method will be called by the Windows installer when this dll is added to an
        /// installation package and the dll has been installed..
        /// </summary>
        /// <param name="stateSaver">Required parameter</param>
        public override void Install(IDictionary stateSaver)
        {
            //MessageBox.Show("The install function for Custoemr Installer has been called", "Installer", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
            log.Debug("Custom Install called with stateSaver value:" + stateSaver);
            base.Install(stateSaver);
            //UpdateDataBase(stateSaver);
        }

        public void UpdateDataBase(IDictionary stateSaver)
        {
            try
            {
                log.Debug("UpdateDataBase() called");
                Updater.Common.DatabaseInstaller l_DatabaseInstaller = new Updater.Common.DatabaseInstaller();
                if (!l_DatabaseInstaller.Install())
                {
                    this.Rollback(stateSaver);
                }
            }
            catch (Exception exception)
            {
                this.Rollback(stateSaver);
                log.Error("Error identified during Update of database, RollBack() called with stateSaver value:" + stateSaver, exception);
            }
        }

    }
}
